﻿using MediatR;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using PublicClass;
using S.RBAC.Domain.Dto;
using S.RBAC.Domain.Help;
using S.RBAC.Domain.Model;
using S.RBAC.Infrastructure.Interface;
using S.RBAC.Read.Api.Application.Command.DepartmentCommand;

namespace S.RBAC.Read.Api.Controllers
{
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class DepartmentController : ControllerBase
    {
        protected readonly IDepartmentRepository _department;
        protected readonly IMediator _mediator;

        public DepartmentController(IDepartmentRepository department, IMediator mediator)
        {
            _department = department;
            _mediator = mediator;
        }


        //[HttpGet]
        //public async Task<List<MenuItem>> GetDepartmentName(int pId = 0)
        //{
        //    List<Department> departments = await _department.GetInfoDepartment(t => t.PId == pId);

        //    List<MenuItem> menuItems=departments.Select(gt=>new MenuItem
        //    {
        //        Value=gt.DepartId.ToString(),
        //        Label=gt.DepartName,

        //        Children=GetDepartmentName(gt.DepartId).? GetDepartmentName(gt.DepartId):null
        //    })
        //}

        /// <summary>
        /// 获取部门信息树型列表
        /// </summary>
        /// <param name="command"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<List<MenuItem>> GetDepartmentName([FromQuery] DepartmentGetNameCommand command)
        {
            return await _mediator.Send(command);
        }

        /// <summary>
        /// 获取部门名称
        /// </summary>
        /// <param name="command"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<List<SelectList>> GetDepartmentInfo([FromQuery] DepartmentGetInfoCommand command)
        {
            return await _mediator.Send(command);
        }

        /// <summary>
        /// 获取部门信息列表
        /// </summary>
        /// <param name="command"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<PageInfo<DepartmentDto>> GetAllDepartment([FromQuery] DepartmentGetAllCommand command)
        {
            return await _mediator.Send(command);
        }
    }
}
